package cn.hy.properties;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

@Configuration
public class PlaceHolderConfig {


    // 只能通过 ${...}  取值
//    @Bean
//    public PropertyPlaceholderConfigurer propertiess() {
//        PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
//        Resource[] resources = new ClassPathResource[]{new ClassPathResource("hy.properties")};
//        ppc.setLocations(resources);
//        ppc.setIgnoreUnresolvablePlaceholders(true);
//        return ppc;
//    }


    @Bean
    public PropertySourcesPlaceholderConfigurer properties() {
        PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
        Resource[] resources = new ClassPathResource[]{new ClassPathResource("hy.properties")};
        pspc.setLocations(resources);
        pspc.setIgnoreUnresolvablePlaceholders(true);
        return pspc;
    }
}
